package com.tboss.template.common.dto;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;

public class NavigationDto implements Serializable {

	private static final long serialVersionUID = 4775899625617859321L;
	private int blockFirstPage;	//블럭 내의 처음 페이지 번호..
    private int blockLastPage;	//블럭 내의 마지막 페이지 번호..
    private int nextBlockFirstPage;		//다음 블럭 처음 페이지 번호..
    private int prevBlockLastPage;		//이전 블럭 마지막 페이지 번호..
    private int currentPage;	//현재 페이지 번호..
    private int lastPage;		//마지막 페이지 번호..
    private int rowPerPage;		//한페이지에 보여지는 줄수..
    private int pageBlock;		//블럭 페이지 번호 갯수..
    private int currentBlock;	//현재 페이지의 블럭 번호..
    private int lastBlock;		//마지막 블럭 번호..
    private int prevBlock;	//이전 블럭 번호..
    private int nextBlock;		//다음 블럭 번호..
    private int totalRow;		//총 데이타수..
    private int indexNo;		//게시번호..
    private Collection<Integer> pageNumCol;
    
    public NavigationDto(int totalRow, int rows, int currentPage){//pageList
        
    	if(rows != 10){
    		this.rowPerPage = rows;
    	}else{ this.rowPerPage = 10; }        
        this.pageBlock = 10;
        this.totalRow = totalRow;
        this.currentPage = currentPage;
    	
        if(currentPage == 0){ this.currentPage = 1; }
        lastPage = (int)Math.ceil((double)getTotalRow() / (double)getRowPerPage());        
        if(lastPage < this.currentPage){ this.currentPage = lastPage; }
        if(this.currentPage == 0){ this.currentPage = 1; }
        
        //이전 블럭 마지막 페이지 구하기..
        int pre = (this.currentPage/pageBlock);
        if((this.currentPage % pageBlock) == 0){ pre = pre - 1; }
        if(pre == 0){ prevBlockLastPage = 1;
        }else{ prevBlockLastPage = (pre * pageBlock); }
        if(prevBlockLastPage < 1){ prevBlockLastPage = 0; }
        
        //다음 블럭 처음 페이지 구하기.
        nextBlockFirstPage = (pre + 1) * pageBlock + 1;
        if(nextBlockFirstPage > lastPage){ nextBlockFirstPage = lastPage; }

        //페이지 시작 페이지 번호..
        blockFirstPage = pre * pageBlock + 1;
        blockLastPage = (pre + 1) * pageBlock;
        
        if(blockLastPage > lastPage){ blockLastPage = lastPage; }
        
        pageNumCol = new ArrayList<Integer>();
        if(this.currentPage > 0){
	        for(int pageNum = blockFirstPage; blockLastPage >= pageNum; pageNum++)
	            pageNumCol.add(new Integer(pageNum));
        }

        this.currentBlock = (int)Math.ceil((double)currentPage / (double)(pageBlock));
        this.lastBlock = (int)Math.ceil((double)lastPage / (double)(pageBlock));
        this.prevBlock = (this.currentBlock > 1) ? (this.currentBlock - 1) : 1;
        this.nextBlock = (this.currentBlock < this.lastBlock) ?  (this.currentBlock + 1) : this.lastBlock;
    }

    public int getIndexNo() { 
    	this.indexNo = totalRow - (currentPage - 1) * rowPerPage;
    	return this.indexNo; 
    }
  	public int getBlockFirstPage() { return blockFirstPage; }
    public int getBlockLastPage() { return blockLastPage; }
	public int getCurrentPage() { return currentPage; }
	public int getNextBlockFirstPage() { return nextBlockFirstPage; }
	public int getPrevBlockLastPage() { return prevBlockLastPage; }
	public int getLastPage() { return lastPage; }
	public int getRowPerPage() { return rowPerPage; }
	public int getPageBlock() { return pageBlock; }
	public int getTotalRow() { return totalRow; }
	public Collection<Integer> getPageNumCol() { return pageNumCol; }
	public int getCurrentBlock() { return currentBlock; }
	public int getLastBlock() { return lastBlock; }
	public int getPrevBlock() { return prevBlock; }
	public int getNextBlock() { return nextBlock; }
	
	public void setIndexNo(int indexNo) { this.indexNo = indexNo; }
	public void setBlockFirstPage(int blockFirstPage) { this.blockFirstPage = blockFirstPage; }
	public void setBlockLastPage(int blockLastPage) { this.blockLastPage = blockLastPage; }
	public void setCurrentPage(int currentPage) { this.currentPage = currentPage; }
	public void setNextBlockFirstPage(int nextBlockFirstPage) { this.nextBlockFirstPage = nextBlockFirstPage; }
	public void setPrevBlockLastPage(int prevBlockLastPage) { this.prevBlockLastPage = prevBlockLastPage; }
	public void setLastPage(int lastPage) { this.lastPage = lastPage; }
	public void setRowPerPage(int rowPerPage) { this.rowPerPage = rowPerPage; }
	public void setPageBlock(int pageBlock) { this.pageBlock = pageBlock; }
	public void setTotalRow(int totalRow) { this.totalRow = totalRow; }
	public void setPageNumCol(Collection<Integer> pageNumCol) { this.pageNumCol = pageNumCol; }
    
}
